package com.tms.springboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tms.springboot.base.pojo.PdTransportLineType;
import com.tms.springboot.mapper.PdTransportLineTypeMapper;
import com.tms.springboot.service.PdTransportLineTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 线路类型表 服务实现类
 * </p>
 *
 * @author cjj
 * @since 2023-06-14
 */
@Service
public class PdTransportLineTypeServiceImpl extends ServiceImpl<PdTransportLineTypeMapper, PdTransportLineType> implements PdTransportLineTypeService {

    @Autowired
    private PdTransportLineTypeMapper transportLineTypeMapper;

    /**
     * todo 根据条件查询线路类型，分页
     *
     * @param currentPage       当前页码
     * @param pageSize          每页显示条数
     * @param transportLineType 查询条件
     * @return PageInfo<PdTransportLineType>
     */
    @Override
    public PageInfo<PdTransportLineType> queryByConditionAndPage(Integer currentPage, Integer pageSize, PdTransportLineType transportLineType) {
        LambdaQueryWrapper<PdTransportLineType> wrapper = new LambdaQueryWrapper<>();

        if (transportLineType.getTypeNumber() != null) {
            wrapper.like(PdTransportLineType::getTypeNumber, transportLineType.getTypeNumber());
        }

        if (transportLineType.getName() != null) {
            wrapper.like(PdTransportLineType::getName, transportLineType.getName());
        }

        if (transportLineType.getStartAgencyType() != null) {
            wrapper.eq(PdTransportLineType::getStartAgencyType, transportLineType.getStartAgencyType()).or().eq(PdTransportLineType::getEndAgencyType, transportLineType.getStartAgencyType());
        }

        PageHelper.startPage(currentPage, pageSize);

        return new PageInfo<>(transportLineTypeMapper.selectList(wrapper));
    }
}
